package com.nbsaas.boot.app.rest.convert;

import com.nbsaas.boot.app.api.domain.response.AppRoleMenuResponse;
import com.nbsaas.boot.app.data.entity.AppRoleMenu;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 角色-实体对象转化成响应对象
 */

public class AppRoleMenuResponseConvert implements Converter<AppRoleMenuResponse, AppRoleMenu> {

    @Override
    public AppRoleMenuResponse convert(AppRoleMenu source) {
        AppRoleMenuResponse result = new AppRoleMenuResponse();
        BeanDataUtils.copyProperties(source, result);
        if (source.getApp() != null) {
            result.setApp(source.getApp().getId());
        }
        if (source.getRole() != null) {
            result.setRole(source.getRole().getId());
        }

        try {
            if (source.getApp() != null) {
                result.setAppName(source.getApp().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getRole() != null) {
                result.setRoleName(source.getRole().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getMenu() != null) {
                result.setMenuName(source.getMenu().getName());
            }
        } catch (Exception ignored) {
        }

        if (source.getMenu() != null) {
            result.setMenu(source.getMenu().getId());
        }
        return result;
    }

}

